package vip.xumy.core.utils;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**	All rights reserved
 *	author:mengyxu
 *	date:2019年5月25日
 *
 * 	处理json数据的工具类
 */

public class JsonUtil {
	
	private JsonUtil(){
		//Add a private constructor to hide the implicit public one.
	}
	
	public static Map<String, String> toStringMap(String jsonStr){
		return JSON.parseObject(jsonStr,new TypeReference<Map<String, String>>(){} );
	}
	
	public static List<Map<String, String>> toStirngMapList(String jsonStr){
		return JSON.parseObject(jsonStr, new TypeReference<List<Map<String,String>>>(){});
	}
	
	public static Map<String,List<Map<String, String>>> toMapStirngMapList(String jsonStr){
		return JSON.parseObject(jsonStr, new TypeReference<Map<String,List<Map<String, String>>>>(){});
	}
	
	public static List<String> toStringList(String jsonStr){
		return JSON.parseObject(jsonStr, new TypeReference<List<String>>(){});
	}
	
	public static List<Integer> toIntegerList(String jsonStr){
		return JSON.parseObject(jsonStr, new TypeReference<List<Integer>>(){});
	}
	
	public static<T> List<T> toEntityList(Class<T> clazz, String jsonStr){
		return JSON.parseArray(jsonStr, clazz);
	}
	
	public static<T> T toEntity(Class<T> clazz, String jsonStr){
		return JSON.parseObject(jsonStr, clazz);
	}
	
	public static<T,E> Map<T, E> toEntiryMap(String jsonStr){
		return JSON.parseObject(jsonStr, new TypeReference<Map<T, E>>(){});
	}
	
}
